package LC.nums.remove;

import java.util.Arrays;

public class LC977 {
    public static void main(String[] args) {
        int[] nums = {-4, -1, 0, 3, 10};
        sortedSquares(nums);
    }

    /**
     * @param nums
     * @return
     */
    public static int[] sortedSquares(int[] nums) {
        int[] ints = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            ints[i] = nums[i] * nums[i];
        }
        Arrays.sort(ints);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
        return ints;
    }

    /**
     * @param nums
     * @return
     */
    public static int[] sortedSquaresTwo(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int temp = nums.length - 1;
        int[] ints = new int[nums.length];
        while (left <= right) {
            if (nums[left] * nums[left] < nums[right] * nums[right]) {
                ints[temp] = nums[right] * nums[right];
                temp--;
                right--;
            } else {
                ints[temp] = nums[left] * nums[left];
                temp--;
                left++;
            }
        }
        return ints;
    }
}
